<?php

	class Jstring{
		
		function __construct($string){
			$this->string = $string;
			$this->mode = '';
		}
		
		function get($k){
			switch($k){	
				case 'escapeHtml':
					return htmlentities($this->string);
				case 'unescapeHtml':
					return html_entity_decode($this->string);
				case 'encodeUri':
					return urlencode($this->string);
				case 'decodeUri':
					return urldecode($this->string);
				case 'length':
					return strlen($this->string);
				case 'toInteger':
					return intval($this->string);
				case 'substr':
					$this->mode = 'substr';
					return $this;
				case 'bytesize':
					return bytesize($this->string);
				case 'toUTCString':
					return date('r', $this->string);
			}
			if(intval($k) == $k){
				$k = intval($k);
				switch($this->mode){
					case 'substr':
						if($k) return new Jstring(substr($this->string, $k));
						$this->mode = '';
						return $this;
					default:
						return substr($this->string, 0, $k);
					
				}
			}
		}
		
		function __tostring(){
			return $this->string;	
		}
	
	}

